home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_14644.txt < prev    next >
Text File  |  1991-02-27  |  2KB  |  32 lines

  1. -- card: 14644 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10.     Person  *person;
  11.  
  12.     person = new(Person);
  13.  
  14. C is case-sensitive, so it is legal to declare a variable - person - of type Person.  In this case, the '*' ("that which is pointed to by") operator is used to indicate that person is a POINTER to a Person object.  A pointer is a variable (usually using a long integer internal representation) which may contain the address of a value.  Therefore, this declaration only allocates space for a machine address, NOT a Person object or its instance variables.  (In truth, the Macintosh implementation of an "indirect" object is slightly different, but this will not concern us quite yet*.)
  15.  
  16. The 'new()' function is contained in the oops library in TC and is declared in the file oops.h.  (In C++, 'new' is an operator rather than a function, so no declaration is needed.)  In this case, it allocates space for a Person object (i.e., two integer instance variables plus "housekeeping" values used by TC) and returns the machine address where this newly-created object begins.  The object may be accessed via the person pointer as discussed below.
  17.  
  18. -- part contents for background part 7
  19. ----- text -----
  20. 34
  21.  
  22. -- part contents for background part 27
  23. ----- text -----
  24. Macintosh memory management
  25.  
  26. -- part contents for background part 20
  27. ----- text -----
  28. Macintosh memory management - p123
  29.  
  30. -- part contents for background part 29
  31. ----- text -----
  32. 38494